<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>报销单据录入</title>
		<script type="text/javascript">
			$(document).ready(function() {
				$('#dialogPanel').omBorderLayout({
					panels : [{
						id : 'officesTreePanel',
						title : '处室',
						region : 'west',
						width : 150,
						height : 550
					}, {
						id : 'nameTreePanel',
						title : '职工',
						region : 'center',
						width : 150,
						hight : 550
					}, {
						id : 'selectedPanel',
						title : '选择',
						region : 'east',
						width : 150,
						height : 550
					}]
				});
				$('#officesTree').omTree({
					dataSource : 'json/offices.json',
					onClick : function(node, event) {
						$('#nameTree').omTree('setData', 'getStuffBySelectController.do?office=' + node.text);
						$('#nameTree').omTree('refresh');
					}
				});
				$('#nameTree').omTree({
					onClick : function(node, event) {
						$('#selection').text(node.text);
					}
				});
				$('#dialog').omDialog({
					autoOpen : false,
					modal : true,
					width : 490,
					buttons : [{
						'text' : '选择',
						click : function() {
							node = $('#nameTree').omTree('getSelected');
							$('#name').val(node.text);
							$('#sid').val(node.sid);
							$(this).omDialog('close');
						}
					}, {
						'text' : '关闭',
						click : function() {
							$('#name').val('');
							$('#sid').val('');
							$(this).omDialog('close');
						}
					}]
				});
				$('#openDialog').bind('click', function() {
					$('#dialog').omDialog('open');
				});
				$('#amount').omNumberField({});
				$('#algorithm').omNumberField({
					alowDecimals : false,
					disabled : true
				});
				$('#reimbursedRatio').omNumberField({
					disabled : true
				});
				$('#date').omCalendar({
					dataFromat : 'yy-mm-dd'
				});
				$('#startDate').omCalendar({
					dataFromat : 'yy-mm-dd',
					disabled : true
				});
				$('#endDate').omCalendar({
					dataFromat : 'yy-mm-dd',
					disabled : true
				});
				$('#type').omCombo({
					dataSource : 'json/type.json',
					onValueChange : function(target, newValue, oldValue, event) {
						if (newValue == '门诊') {
							$('#startDate').omCalendar('disable');
							$('#endDate').omCalendar('disable');
							$('#algorithm').omNumberField('disable');
							$('#reimbursedRatio').omNumberField('disable');
						}
						if (newValue == '住院') {
							$('#startDate').omCalendar('enable');
							$('#endDate').omCalendar('enable');
							$('#algorithm').omNumberField('enable');
							$('#reimbursedRatio').omNumberField('disable');
						}
						if (newValue == '特殊') {
							$('#startDate').omCalendar('disable');
							$('#endDate').omCalendar('disable');
							$('#algorithm').omNumberField('disable');
							$('#reimbursedRatio').omNumberField('enable');
						}
					}
				});
				$('#submitBtn').bind('click', function() {
					$('#reimbursementForm').omAjaxSubmit({
						clearForm : true,
						method : 'post',
						beforeSubmit : function(arr, $form, options) {
							if (arr.name == null || arr.sid) {
								alert('姓名为必填');
								return false;
							}
							if (arr.date == null) {
								alert('请选择日期');
								return false;
							}
							if (arr.type == '住院') {
								if (arr.startDate == null) {
									alert('请选择住院日期');
									return false;
								}
								if (arr.endDate == null) {
									alert('请选择出院日期');
									return false;
								}
								if (arr.algorithm == null) {
									alert('床位费不能为空');
									return false;
								}
							}
							if (arr.type == '特殊') {
								if (arr.reimbursedRatio == null) {
									alert('报销比例不能为空');
									return false;
								}
							}
						},
						success : function(responseText, statusText, xhr, $form) {
							if(responseText.success==true){
								alert('添加成功');
							}
						}
					});
				});
			});
		</script>
	</head>
	<body>
		<form id="reimbursementForm" action="insertReimbursementController.do">
			<label>姓名</label>
			<br>
			<input id="name" readonly/>
			<input id="sid" name="sid" type="hidden"/>
			<input id="openDialog" value="选择" type="button" />
			*
			<br>
			<label>金额</label>*
			<br>
			<input id="amount" name="amount"/>
			<br>
			<label>类型</label>
			<br>
			<input id="type" name="type"/>
			*
			<br>
			<label>入院日期</label>
			<br>
			<input id="startDate" name="startDate" disabled/>
			<br>
			<label>出院日期</label>
			<br>
			<input id="endDate" name="endDate" disabled/>
			<br>
			<label>床位费</label>
			<br>
			<input id="algorithm" name="algorithm" disabled/>
			<br>
			<label>报销比例</label>
			<br>
			<input id="reimbursedRatio" name="reimbursedRatio" disabled/>
			(0~100)
			<br>
			<label>报销内容</label>
			<br>
			<input id="content" name="content"/>
			<br>
			<label>日期</label>
			<br>
			<input id="date" name="date"/>
			*
			<br>
			<p>
				打*的项目为必填
			</p>
			<input id="submitBtn" type="button" value="提交"/>
		</form>
		<div id="dialog">
			<div id="dialogPanel"  style="width:450px; height:600px;">
				<div id="officesTreePanel">
					<div id="officesTree"></div>
				</div>
				<div id="nameTreePanel">
					<div id="nameTree"></div>
				</div>
				<div id="selectedPanel">
					<div id="selection"></div>
				</div>
			</div>
		</div>
	</body>
</html>